<template>
  <div class="stuShowDialog">
    <el-dialog
      title="学业管理"
      :visible.sync="dialogTableVisible"
      @close="handleClose"
    >
      <div v-if="isNoCreateStuShow">
        您的课程学业还未创建
        <el-button type="text" @click="createStuOutcomes">创建学业</el-button>
      </div>
      <OUTCOMESUPLOADFILE v-if="!isNoCreateStuShow && stuworkshowID" :stuworkshowID="stuworkshowID" :currNo="currNo" />
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
const OUTCOMESUPLOADFILE = () =>
  import("@/views/user/user/stuOutcomes/outcomesUploadFile");
export default {
  components: {
    OUTCOMESUPLOADFILE,
  },
  data() {
    return {
      dialogTableVisible: false,
      stuworkshowID: null,
      currNo: null,
      isNoCreateStuShow: false,
    };
  },
  props: {
    showStuShowDialog: Boolean,
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
      stuShowList: (state) => state.stuShow.stuShowList,
      defaultData: (state) => state.stuShow.defaultData,
    }),
  },
  watch: {
    showStuShowDialog(n) {
      this.dialogTableVisible = n;
    },
    stuShowList(n) {
      this.getStuShowWorksShowID();
    },
  },
  created() {
    this.dialogTableVisible = this.showStuShowDialog
    this.currNo = this.$route.params.id;
    this.getStuShowList();
  },
  methods: {
    handleClose() {
      this.$emit("close");
    },
    async getStuShowList() {
      await this.$store.dispatch("stuShow/gStuShowList", {
        userID: this.userInfo.userID,
      });
      if (this.stuShowList) {
        this.getStuShowWorksShowID()
      }
    },
    async createStuOutcomes(row) {
      if (!this.currNo)
        return this.$antdMessage.warning({ content: "缺少currNo,无法创建!" });
      const created = await this.$store.dispatch("stuShow/createStuOutcomes", {
        userID: this.userInfo.userID,
        currNo: this.currNo,
      });
      if (created) {
        this.isNoCreateStuShow = false;
        this.getStuShowWorksShowID();
      }
    },
    async getStuShowWorksShowID() {
      let findStuShow = this.stuShowList?.find(
        (item) => item.currNo == this.currNo
      );
      if (findStuShow) {
        this.stuworkshowID = findStuShow.stuworkshowID;
      } else {
        this.isNoCreateStuShow = true
      }
    },
  },
};
</script>